const util = {};

util.formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
  }

//   时间戳转换年-月-日 星期 时：分：秒
util.formatDate = function (timestamp) { 
    let date = new Date(timestamp)
    let y = date.getFullYear(); //年
    let m = date.getMonth() + 1
    m = m < 10 ? ('0' + m) : m
    let d = date.getDate()
    d = d < 10 ? ('0' + d) : d
    let hour =date.getHours(); 
    let minutes = date.getMinutes();
    minutes = minutes < 10?('0'+minutes):minutes
    let s = date.getSeconds()
    s = s < 10 ? ('0' + s) : s
    const time = `${y}-${m}-${d} ${hour}:${minutes}:${s}`
    return time
 }
// 获取年
 util.getYear=function(dateData){
    let date = new Date(dateData)
    let y = date.getFullYear(); //年
    
    return y
  }

//   获取时分秒
util.getDate = function (dateData) { 
    let date = new Date(dateData)
    let hour =date.getHours(); 
    let minutes = date.getMinutes();
    let s = date.getSeconds()
    s = s < 10 ? ('0' + s) : s
    // const time =  y + '-' + m + '-' + d;
    const time = `${hour}:${minutes}:${s}`
    return time
  }

 export default util
